﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using NLog;
using Service.Menus;
using Service.Menus.Dto;

namespace UI.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MenuController : ControllerBase
    {
        private readonly IMenuService menuService;
        private readonly Logger _logger = LogManager.GetCurrentClassLogger();

        public MenuController(IMenuService menuService)
        {
            this.menuService = menuService;
        }

        [HttpGet]
        public IActionResult Query()
        {
            return Ok(menuService.QueryInfo());
        }

        [HttpGet]
        public IActionResult Quer()
        {
            try
            {
                _logger.Error("这是一条错误信息");
                return Ok();
            }
            catch (System.Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 菜单添加
        /// </summary>
        /// <param name="menuDto"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult Insert(MenuDto menuDto)
        {
            return Ok(menuService.Insert(menuDto));
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public IActionResult Delete(int id)
        {
            return Ok(menuService.Delete(id));
        }

        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult QueryFirst(int id)
        {
            return Ok(menuService.QueryFirst(id));
        }

        /// <summary>
        /// 菜单修改
        /// </summary>
        /// <param name="menuDto"></param>
        /// <returns></returns>
        [HttpPut]
        public IActionResult Update(MenuDto menuDto)
        {
            return Ok(menuService.Update(menuDto));
        }
    }
}
